const users = require('../controllers/user.server.controller');
const articles = require('../controllers/article.server.controller');

module.exports = function (app) {
    app.route('/articles')
        .get(articles.list)
        .post(users.requiresLogin, articles.write);

    app.route('/articles/:articleId')
        .get(articles.read)
        .put(users.requiresLogin, articles.hasAuthorization, articles.update)
        .delete(users.requiresLogin, articles.hasAuthorization, articles.delete);

    app.route('/articles/:articleId/comments')
        .post(users.requiresLogin, articles.writeComments);

    app.route('/articles/:articleId/comments/:commentId')
        .delete(users.requiresLogin, articles.hasConmentsAuthorization, articles.cancelComments);

    app.param('articleId', articles.articleByID);
};
